<?php
include_once '../emag/regras_base.php';
$regras = new RegrasBase();
function testar($tagInteira, $att, $expected){
	global $regras;
	echo "<tr><td>" . str_replace('<', '&lt;', $tagInteira) . "</td>";
	echo "<td>" . str_replace('<', '&lt;', $att) . "</td>";
	$rs = $regras->getAtributo($tagInteira, $att);
	echo "<td>" . str_replace('<', '&lt;', $rs) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}
?>
<!DOCTYPE h1 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Testes</title>
	<style type="text/css">
		td{
			padding: 3px;
			border: 1px solid #ccc;
		}
		.pass{
			background: #efe;
		}
		.fail{
			background: #f00;
		}
	</style>
</head>
<body>
<h1>Recuperando atributo</h1>
<table>
	<tr>
		<th>
			tag inteira
		</th>
		<th>
			att
		</th>
		<th>
			retorno
		</th>
		<th>
			resultado
		</th>
	</tr>
<?php 
$tagInteira	= "<img alt='desc'>";
$att 		= "alt";
$expected 	= 'desc';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img  alt='de   sc'  >";
$att 		= "alt";
$expected 	= 'de   sc';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt='desc' src=img >";
$att 		= "src";
$expected 	= 'img';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt='desc' src=img>";
$att 		= "src";
$expected 	= 'img';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt='desc' src=img/>";
$att 		= "src";
$expected 	= 'img';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt='desc' src=img>";
$att 		= "alt";
$expected 	= 'desc';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt=\"desc\" src=img>";
$att 		= "alt";
$expected 	= 'desc';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt=\"de's'c\" src=img>";
$att 		= "alt";
$expected 	= "de's'c";
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt='de\"s\"c' src=img>";
$att 		= "alt";
$expected 	= 'de"s"c';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img alt=de\"s\"c src=img>";
$att 		= "alt";
$expected 	= 'de"s"c';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img ALT=de\"s\"c src=img>";
$att 		= "alt";
$expected 	= 'de"s"c';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img ALT=DE\"s\"c src=img>";
$att 		= "alt";
$expected 	= 'DE"s"c';
testar($tagInteira, $att, $expected);

$tagInteira	= "<img ALT=DE\"s\"c src=img>";
$att 		= "Alt";
$expected 	= 'DE"s"c';
testar($tagInteira, $att, $expected);
?>
</table>

<h1>Verificar se existe cor (color ou background) em style inline</h1>
<table>
<tr>
	<th>tag inteira</th>
	<th>resultado</th>
</tr>
<?php 
function styleInline($tagInteira, $expected){
	global $regras;
	$rs = $regras->verificaCorStyleInline($tagInteira);
	echo "<tr><td>" . str_replace('<', '&lt;', $tagInteira) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}

$tagInteira = '<a style="color: #ddd;">';
styleInline($tagInteira, true);
$tagInteira = '<a style="font: #ddd;">';
styleInline($tagInteira, false);
$tagInteira = '<a style="background: #ddd;">';
styleInline($tagInteira, true);

?>
</table>

<h1>Link de css</h1>
<table>
<tr>
	<th>tag inteira</th>
	<th>resultado</th>
</tr>
<?php 
function linkCss($tagInteira, $expected){
	global $regras;
	$rs = $regras->verificaIsCSS($tagInteira);
	echo "<tr><td>" . str_replace('<', '&lt;', $tagInteira) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}
$tagInteira = '<link href="/phoenix/favicon.ico" rel="shortcut icon" type="image/x-icon" />';
linkCss($tagInteira, false);
  
$tagInteira = '<link type="text/css" rel="stylesheet" href="http://www.gstatic.com/codesite/ph/18091280713519311357/css/ph_core.css">';
linkCss($tagInteira, true);
 
?>
</table>


<h1>gif em src</h1>
<table>
<tr>
	<th>tag inteira</th>
	<th>resultado</th>
</tr>
<?php 
function srcGif($tagInteira, $expected){
	global $regras;
	$rs = $regras->verificaIsGif($tagInteira);
	echo "<tr><td>" . str_replace('<', '&lt;', $tagInteira) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}
$tagInteira = '<img src="teste.png" />';
srcGif($tagInteira, false);
  
$tagInteira = '<img src="teste.gif">';
srcGif($tagInteira, true);

$tagInteira = '<img src="teste.GIF">';
srcGif($tagInteira, true);

$tagInteira = '<img src=teste.Gif>';
srcGif($tagInteira, true);

?>
</table>

<h1>Label for</h1>
<table>
<tr>
	<th>html</th>
	<th>id</th>
	<th>resultado</th>
</tr>
<?php 
function chkLabel($codHTML, $idField, $expected){
	global $regras;
	$rs = $regras->verificaLabel($codHTML, $idField);
	echo "<tr><td>" . str_replace('<', '&lt;', $codHTML) . "</td>";
	echo "<td>" . str_replace('<', '&lt;', $idField) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}
$codHTML = 'koko <label for="teste">knjjd';
chkLabel($codHTML, 'teste', true);
  
$codHTML = '<img src="teste.gif">';
chkLabel($codHTML, 'teste', false);

?>
</table>

<h1>Label for, com tag</h1>
<table>
<tr>
	<th>html</th>
	<th>tag</th>
	<th>resultado</th>
</tr>
<?php 
function chkLabelTag($codHTML, $tag, $expected){
	global $regras;
	$rs = $regras->verificaLabelTag($codHTML, $tag);
	echo "<tr><td>" . str_replace('<', '&lt;', $codHTML) . "</td>";
	echo "<td>" . str_replace('<', '&lt;', $tag) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}
$codHTML = 'koko <label for="teste">knjjd <input type="text" id="teste" />';
chkLabelTag($codHTML, '<input type="text" id="teste" />', true);
  
$codHTML = '<img src="teste.gif"><input type="text" id="teste" />';
chkLabelTag($codHTML, '<input type="text" id="teste" />', false);

$codHTML = '<label for="teste"><input type="radio" id="teste" />';
chkLabelTag($codHTML, '<input type="radio" id="teste" />', true);

$codHTML = '<img src="teste.gif"><input type="submit" id="teste" />';
chkLabelTag($codHTML, '<input type="submit" id="teste" />', true);

$codHTML = '<img src="teste.gif">';
chkLabelTag($codHTML, '<select id="teste" />', false);

$codHTML = '<img src="teste.gif"><label for="tested">knjjd ';
chkLabelTag($codHTML, '<select id="teste" />', false);

$codHTML = 'koko <label for="teste">knjjd ';
chkLabelTag($codHTML, '<select id="teste" />', true);

$codHTML = '<img src="teste.gif"><label for="tested">knjjd ';
chkLabelTag($codHTML, '<textarea id="teste" />', false);

$codHTML = '<img src="teste.gif"><label for="tested">knjjd <label for="teste">';
chkLabelTag($codHTML, '<textarea id="teste" />', true);

?>
</table>

<h1>Lang</h1>
<table>
<tr>
	<th>html</th>
	<th>id</th>
	<th>resultado</th>
</tr>
<?php 
function chkLang($tag, $expected){
	global $regras;
	$rs = $regras->verificaLang($tag);
	echo "<tr><td>" . str_replace('<', '&lt;', $tag) . "</td>";
	if($rs == $expected){
		echo "<td class=\"pass\">Passou</td>";
	}else{
		echo "<td class=\"fail\">Reprovado</td>";
	}
	echo "</tr>";
}
$tag = '<html>';
chkLang($tag, false);

$tag = '<html lang="">';
chkLang($tag, false);

$tag = '<html lang="pt-br">';
chkLang($tag, true);

$tag = '<HTML LANG="pt-BR">';
chkLang($tag, true);
?>
</table>
</body>
</html>